package servlet;

import java.io.IOException;
import java.util.Timer;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import server.TCPDesktopServer;
import util.ThreadLocal;

public class MyServlet extends HttpServlet
{
    private ThreadLocal localObjectInThisThread = new ThreadLocal();
    
    private static final long serialVersionUID = 1L;
    
    Timer timer;
    
    public MyServlet()
    {
        timer = new Timer();
    }
    
    public void init()
        throws ServletException
    {
        
        timer.schedule(new MyTask(), 1800000, 1800000); // 每半天保存一次数据
        Thread desktopServerThread = new Thread(new TCPDesktopServer());
        desktopServerThread.start();
        System.out.println("启动结束");
    }
    
    /*
     * localObjectInThisThread.set(HibernateSessionFactory.getSession()); doSomething(); } public void doSomething() {
     * org.hibernate.Session thisThreadsSession = (HibernateUtil.getSessionFactory().getCurrentSession())
     * 
     * localObjectInThisThread.get();
     * 
     * //基于当前session的存取操作 Transaction tx=thisThreadsSession.beginTransaction(); Stringsql=
     * "INSERT INTO tHistory20131001(id,mark,hData,deviceId)  VALUES('9208582a1ba84e238c9cdd909d7e75f7',0,'3.7','test55555')"
     * ; SQLQuery query = thisThreadsSession.createSQLQuery(sql); query.executeUpdate(); tx.commit();
     * thisThreadsSession.flush(); }
     */
    public void doGet(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
        throws ServletException, IOException
    {
    }
    
    public void destory()
    {
        timer.cancel();
    }
}
